﻿using Jay.Sc2.Bof.Lib.State;
using Jay.Sc2.Bof.Lib.Tools;

namespace Jay.Sc2.Bof.Lib.Action.Protoss
{
	public class ActionProduceProbe : ActionProduceProtoss
	{
		public static ActionProduceProbe Instance = new ActionProduceProbe();

		private ActionProduceProbe() : base(17, 50, 0, 1) { }

		public override int AvailableProducer(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return state.Nexus.AvailableForProduction;
		}

		public override bool CanExecute(IBuildOrder bo)
		{
			return bo.State.Workers < IncomeUtil.GetSaturationWorkerCount(bo.State.MineralPatches, bo.State.GasBuilding.Count) && base.CanExecute(bo);
		}

		public override bool HaveTechnology(IBuildOrder bo) { return true; }

		public void OnProductionFinished(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			state.Probe++;
			state.WorkersOnMinerals++;
		}

		public override void Execute(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			base.Execute(bo);
			state.Nexus.Production++;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnProbe", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ProtossState ibostate = ibo.State as ProtossState;
				ibostate.Nexus.Production--;
				OnProductionFinished(ibo);
			}));

		}
	}
}
